package org.akomantoso.core.data;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.akomantoso.core.data.attribute.Core;
import org.akomantoso.core.data.attribute.IdReq;
import org.akomantoso.core.data.attribute.LinkOpt;
import org.akomantoso.core.data.attribute.Refers;
import org.akomantoso.core.data.attribute.Value;
import org.akomantoso.core.io.Externalizable;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;

/**
 * The complex type countType lists all the properties associated to elements of parliamentary count.
 * 
 * <pre>
 * 	<xsd:complexType name="countType">
 * 		<xsd:choice>
 * 			<xsd:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
 * 		</xsd:choice>
 * 		<xsd:attributeGroup ref="core"/>
 * 		<xsd:attributeGroup ref="idreq"/>
 * 		<xsd:attributeGroup ref="value"/>
 * 		<xsd:attributeGroup ref="refers"/>
 * 		<xsd:attributeGroup ref="linkopt"/>
 * 	</xsd:complexType>
 * </pre>
 * 
 */
public class CountType implements Core, IdReq, Value, Refers, LinkOpt, Externalizable {

	// Mandatory
	private String _id;
	// Optional
	private String _evolvingId;
	// Mandatory
	private String _value;
	// Optional
	private String _refersTo;
	// Optional
	private String _href;

	// Mandatory (min 1).
	private final List<ParliamentaryAnalysisTypeElement> _elements = new ArrayList<ParliamentaryAnalysisTypeElement>(4);

	/**
	 * @see org.akomantoso.core.data.attribute.IdReq#getId()
	 */
	@Override
	public String getId() {
		return _id;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.IdReq#setId(java.lang.String)
	 */
	@Override
	public void setId(String id) {
		_id = id;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.IdReq#getEvolvingId()
	 */
	@Override
	public String getEvolvingId() {
		return _evolvingId;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.IdReq#setEvolvingId(java.lang.String)
	 */
	@Override
	public void setEvolvingId(String evolvingId) {
		_evolvingId = evolvingId;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Value#getValue()
	 */
	@Override
	public String getValue() {
		return _value;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Value#setValue(java.lang.String)
	 */
	@Override
	public void setValue(String value) {
		_value = value;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.LinkOpt#getHref()
	 */
	@Override
	public String getHref() {
		return _href;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.LinkOpt#setHref(java.lang.String)
	 */
	@Override
	public void setHref(String href) {
		_href = href;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Refers#getRefersTo()
	 */
	@Override
	public String getRefersTo() {
		return _refersTo;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Refers#setRefersTo(java.lang.String)
	 */
	@Override
	public void setRefersTo(String refersTo) {
		_refersTo = refersTo;
	}

	public List<ParliamentaryAnalysisTypeElement> getElements() {
		return _elements;
	}

	/**
	 * @see org.akomantoso.core.io.Externalizable#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <T extends Output> void writeExternal(T out) throws IOException {
		OutputUtil.writeIdReq(out, this);
		OutputUtil.writeRefers(out, this);
		OutputUtil.writeValue(out, this);
		OutputUtil.writeLinkOpt(out, this);
	}

	/**
	 * @see org.akomantoso.core.io.Externalizable#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <T extends Input> void readExternal(T in) throws IOException {
		_id = in.readAttribute(IdReq.ATTRIBUTE_ID);
		_evolvingId = in.readAttribute(IdReq.ATTRIBUTE_EVOLVING_ID);
		_href = in.readAttribute(LinkOpt.ATTRIBUTE);
		_value = in.readAttribute(Value.ATTRIBUTE);
		_refersTo = in.readAttribute(Refers.ATTRIBUTE);
	}
}
